#include <iostream>
#include <stack>
#include <algorithm>
#include <climits>

using namespace std;

const int N=1e5+10;

int n;
int h[N],l[N],r[N];

int main() 
{
	while(cin>>n)
	{
		if(n==0) break;
		
		for(int i=1;i<=n;i++) cin>>h[i];
		
		stack<int> s1;
		for(int i=1;i<=n;i++)
		{
			while(s1.size()&&h[i]<=h[s1.top()]) s1.pop();
			if(s1.size()) l[i]=s1.top();
			else l[i]=0; 
			s1.push(i);
		}
		stack<int> s2;
		for(int i=n;i>=1;i--)
		{
			while(s2.size()&&h[i]<=h[s2.top()]) s2.pop();
			if(s2.size()) r[i]=s2.top();
			else r[i]=n+1;
			s2.push(i);
		}
		
		long long ret=INT_MIN;
		for(int i=1;i<=n;i++)
		{
			long long cur=h[i]*(r[i]-l[i]-1);
			ret=max(ret,cur);
		}
		
		cout<<ret<<endl;
	}
	
	return 0;
}
